<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户维护页面</title>
<script type="text/javascript" src="${path}/js/scripts/bootstart.js"></script>
<link rel="stylesheet" type="text/css" href="${path}/css/focus.css" />
</head>
<body>
	<form id="userForm" method="post">
		<div style="display: none;">
			<input name="userId" class="mini-textbox" /> <input name="roleName"
				class="mini-textbox" id="roleName" /> <input name="addTime"
				class="mini-textbox" /> <input name="userStatus"
				class="mini-textbox" /> <input name="imageUrl" class="mini-textbox" />
			<input name="extend1" class="mini-textbox" /> <input name="extend2"
				class="mini-textbox" /> <input name="isLocked" class="mini-textbox" />
			<input name="userType" class="mini-textbox" />
			<c:if test="${param.flag=='edit'}">
				<input name="password" class="mini-hidden" />
			</c:if>
		</div>
		<div class="form_nav">
			<table width="100%" cellpadding="4" cellspacing="0">
				<tr>
					<td width="8%" class="xx_bt nonebor">用户名称:</td>
					<td width="25%" class="xx_type  nonebor"><input
						name="userName" style="width: 90%;" class="mini-textbox"
						required="true"  vtype="maxLength:10" /><span
						class="required_cls">*</span></td>
					<td class="xx_bt">用户账号:</td>
					<td class="xx_type"><input name="jobNo"
						onvalidation="onJobNoValidation" style="width: 90%;" id="jobno"
						class="mini-textbox" required="true"  vtype="maxLength:20"/><span class="required_cls">*</span></td>
				</tr>
				<tr>
					<c:choose>
						<c:when test="${param.flag=='edit'}">
							<td width="8%" class="xx_bt nonebor">用户密码:</td>
							<td width="25%" class="xx_type nonebor" style="text-align: left;"><font
								color="red">不可修改</font></td>
							<td width="8%" class="xx_bt nonebor">确认密码:</td>
							<td width="25%" class="xx_type nonebor" style="text-align: left;"><font
								color="red">不可修改</font></td>
						</c:when>
						<c:otherwise>
							<td width="8%" class="xx_bt nonebor">用户密码:</td>
							<td width="25%" class="xx_type nonebor"><input
								name="password" style="width: 90%;" class="mini-password"
								required="true" id="pwd" vtype="minLength:6" /><span
								class="required_cls">*</span></td>
							<td width="8%" class="xx_bt nonebor">确认密码:</td>
							<td width="25%" class="xx_type nonebor"><input
								class="mini-password" required="true" id="repwd"
								style="width: 90%;" onvalidation="userform.validPwd"
								vtype="minLength:6" /><span class="required_cls">*</span></td>
						</c:otherwise>
					</c:choose>
				</tr>
				<tr>
					<td class="xx_bt">用户角色:</td>
					<td class="xx_type"><input id="showrole" style="width: 90%;"
						name="roleId" class="mini-buttonedit"
						requiredErrorText="角色不能为空，请先选择角色" allowInput="false"
						onbuttonclick="userform.onButtonEdit" emptyText="请先选择角色" /><span
						class="required_cls">*</span></td>
					<td class="xx_bt">联系电话:</td>
					<td class="xx_type"><input name="telephone"
						style="width: 90%;" class="mini-textbox"  vtype="maxLength:20"/></td>
				</tr>
				<tr>
					<td class="xx_bt">用户邮箱:</td>
					<td class="xx_type"><input name="email" id="email"
						style="width: 90%;" class="mini-textbox" vtype="email"  vtype="maxLength:50"/></td>
					<td class="xx_bt">用户生日:</td>
					<td class="xx_type"><input name="birthday"
						class="mini-datepicker" format="yyyy-MM-dd " allowInput="false"
						style="width: 90%;" /></td>
				</tr>
				<tr>
					<td class="xx_bt">用户备注:</td>
					<td colspan="3" class="xx_type"><input name="remark"
						class="mini-textarea" style="width: 96%;"  vtype="maxLength:255"/></td>
				</tr>
			</table>
		</div>
		<div style="text-align: center; padding: 10px;">
			<a class="mini-button" onclick="userform.saveData" id="sub_button"
				iconCls="icon-save" style="width: 60px; margin-right: 20px;">保存</a>
			<a iconCls="icon-cancel" class="mini-button"
				onclick="$.form.onCancel()" style="width: 60px;">取消</a>
		</div>
	</form>
	<script type="text/javascript" src="${path}/js/scripts/dataform.js"></script>
	<script type="text/javascript">
		mini.parse();
		var staticjobno = "";//验证jobno
		$(function() {
			$.form.init(); //初始化表单
			window.userform = {};
			userform.saveData = function() {
				//验证工号是否已被使用
				var jobobj = mini.get("jobno");
				if (jobobj.value == null || jobobj.value == "") {
					jobobj.setErrorText("用户账号不能为空!");
					jobobj.setIsValid(false);
					return;
				}
				if ("${param.flag}" == "edit" && staticjobno == jobobj.value) {
					jobobj.setIsValid(true);
					var form = new mini.Form("#userForm");
					form.validate();
					if (form.isValid() == false) {
						return;
					}
					mini.get("sub_button").disable();
					$.form.saveData({
						url : "${path}/user/mgr/addUser",
						id : "userForm",
						showMsg : true
					//是否显示提示信息
					});
				} else {
					$.ajax({
						url : "${path}/user/mgr/validationJobNo",
						cache : false,
						type : "post",
						data : "jobno=" + jobobj.value,
						success : function(obj) {
							if (obj == "true") {
								jobobj.setErrorText("该用户账号已被使用，不可重复!");
								jobobj.setIsValid(false);
							} else {
								jobobj.setIsValid(true);
								var form = new mini.Form("#userForm");
								form.validate();
								if (form.isValid() == false) {
									return;
								}
								mini.get("sub_button").disable();
								$.form.saveData({
									url : "${path}/user/mgr/addUser",
									id : "userForm",
									showMsg : true
								//是否显示提示信息
								});
							}
						}
					});
				}
			};
			//确认密码验证
			userform.validPwd = function(e) {
				var pwd = mini.get("pwd").getValue();
				if (e.value != pwd) {
					e.errorText = "两次密码输入不一致！";
					e.isValid = false;
					return false;
				}
				return true;
			};

			//显示角色选择框
			userform.onButtonEdit = function(e) {
				var btnEdit = this;
				mini.open({
					url : "${path}/user/mgr/showRole",
					title : "多选角色列表",
					width : 500,
					height : 380,
					ondestroy : function(action) {
						if (action == "ok") {
							var iframe = this.getIFrameEl();
							var data = iframe.contentWindow.GetData();
							data = mini.clone(data);
							btnEdit.setValue(data.id);
							btnEdit.setText(data.text);
							mini.get("roleName").setValue(data.text);
						}
					}
				});
			};
		});
		//页面初始化时，执行该函数资源类型
		$.form.loadFormSuccess = function() {
			mini.get("showrole").setText(mini.get("roleName").value);
			staticjobno = mini.get("jobno").value;
		};
		function onJobNoValidation(e) {
			if (e.isValid) {
				if (isEnglishAndNumber(e.value) == false) {
					e.errorText = "请输入英文、数字或者两者组合";
					e.isValid = false;
				}
			}
		}
		/* 是否英文+数字 */
		function isEnglishAndNumber(v) {
			var re = new RegExp("^[0-9a-zA-Z\_]+$");
			if (re.test(v))
				return true;
			return false;
		}
	</script>
</body>
</html>